# Create your views here.
import base64

from django.http import JsonResponse


# base64编码字符串
def base64_encode(request):
    test_string = request.GET.get('test_string')
    encode_str = base64.b64encode(test_string.encode('utf-8'))
    res = str(encode_str, 'utf-8')
    ccm_result = {
        'code': 200,
        'msg': '加密完成！！！！！',
        'data': {
            'test_string': res,
        }
    }
    return JsonResponse(ccm_result)


def base64_decode(request):
    test_string = request.GET.get('test_string')
    decode_str = base64.b64decode(test_string.encode('utf-8'))
    res = str(decode_str, 'utf-8')
    ccm_result = {
        'code': 200,
        'msg': '解密完成！！！！！',
        'data': {
            'test_string': res,
        }
    }
    return JsonResponse(ccm_result)


